#include "adddevicewidget.h"
#include "ui_adddevicewidget.h"
#include "mywidgetfactory.h"
#include "mytcpproxy.h"
#include <QMessageBox>

AddDeviceWidget::AddDeviceWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AddDeviceWidget)
{
    ui->setupUi(this);
}

AddDeviceWidget::~AddDeviceWidget()
{
    delete ui;
}

void AddDeviceWidget::show(QString &userid)
{
    QWidget::show();
    this->userid = userid;
    //
}

void AddDeviceWidget::on_pushButton_clicked()
{
    MyTcpProxy::sndDevAdd(userid, ui->lineEdit->text(),ui->lineEdit_2->text(),ui->lineEdit_3->text());
}

void AddDeviceWidget::on_pushButton_2_clicked()
{
    this->hide();
    MyWidgetFactory::getMainWidget()->show(userid);
}

void AddDeviceWidget::onDevAdd(const bool &ret, const QString &msg)
{
    if(ret){
        QMessageBox::information(this,"设备添加","设备添加成功");
        this->hide();
        MyWidgetFactory::getMainWidget()->show(userid);
    }else{
        QMessageBox::critical(this,"设备添加","设备添加失败");
    }
}
